{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from langgraph.graph import StateGraph\n",
    "from typing import TypedDict\n",
    "\n"
   ]
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "\n",
    "# Define the state schema for the graph.\n",
    "class GraphState(TypedDict):\n",
    "    messages: list[dict]\n",
    "\n",
    "\n",
    "# Define the first node function that processes the state.\n",
    "def process_node(state: GraphState) -> GraphState:\n",
    "    # Process the state by appending a processed message.\n",
    "    new_message = {\"content\": \"Processed message\", \"status\": \"processed\"}\n",
    "    state[\"messages\"].append(new_message)\n",
    "    # Talking Point: This node demonstrates the initial processing step.\n",
    "    return state\n",
    "\n",
    "\n",
    "# Define an additional node function that finalizes the state.\n",
    "def finalize_node(state: GraphState) -> GraphState:\n",
    "    # Further process the state by appending a finalized message.\n",
    "    final_message = {\"content\": \"Finalized message\", \"status\": \"finalized\"}\n",
    "    state[\"messages\"].append(final_message)\n",
    "    # Talking Point: This node shows how subsequent steps can extend the workflow.\n",
    "    return state\n",
    "\n",
    "\n",
    "# Create the StateGraph instance with the defined state schema.\n",
    "graph = StateGraph(GraphState)\n",
    "\n",
    "# Add both nodes to the graph.\n",
    "graph.add_node(\"process\", process_node)\n",
    "graph.add_node(\"finalize\", finalize_node)\n",
    "\n",
    "# Add an edge to connect the \"process\" node to the \"finalize\" node.\n",
    "graph.add_edge(\"process\", \"finalize\")\n",
    "\n",
    "# Set the entry point to \"process\" and the finish point to \"finalize\".\n",
    "graph.set_entry_point(\"process\")\n",
    "graph.set_finish_point(\"finalize\")\n",
    "\n",
    "# Compile the graph into an executable application.\n",
    "app = graph.compile()\n",
    "\n",
    "# Run the graph with an initial state.\n",
    "initial_state = {\"messages\": []}\n",
    "result = app.invoke(initial_state)\n",
    "\n",
    "# Output the final state to observe the accumulated changes.\n",
    "print(\"Final state after graph execution:\", result)\n"
   ],
   "id": "1d69c9063f93e67f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
